Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sun 403 posts 395 karma points
    Aug 22, 2011 @ 11:29
    sun
    2

    Who can tell me what is different between [a=1 and b=1] and [a=1][b=1]?

    <xsl:for-each select="catalog/cd[country='USA' and price > 10]">

      <xsl:for-each select="catalog/cd[country='USA'][ price > 10]">

     

    above two ways, the results will be the same, what is different of them?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 22, 2011 @ 11:42
    Chriztian Steinmeier
    3

    Hi sun,

    Very good question :-)

    The square brackets expression is called a predicate and it acts as a filter on the nodeset that results from the expression up until the predicate occurs - so in your example, the first expression (using the and operator) the processor will collect all <cd> elements and then for each of them, check if it has a <country> node with the value 'USA' and a <price> node with a value greater than 10.

    In the other example, it will find all <cd> elements with a 'USA' <country> node, and only between those, check for a <price> greater than 10.

    So, you see - if the [price > 10] was a more expensive operation (e.g., calling an extension function like DateGreaterThanOrEqualToday(), etc.) it's a good idea to only have that expression evaluated when necessary.

    Hope that explains it.

    /Chriztian

     

Please Sign in or register to post replies

Write your reply to:

Draft